<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('产权信息') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('公司名称')" prop="companyId">
        <el-input
          v-model="queryParams.companyId"
          :placeholder="$t('公司名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('统一信用代码')" prop="creditCode">
        <el-input
          v-model="queryParams.creditCode"
          :placeholder="$t('统一信用代码')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('组织形式')" prop="organizationalForm">
        <el-select v-model="queryParams.organizationalForm" :placeholder="$t('组织形式')" clearable>
          <el-option
            v-for="dict in organizationalOption"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('主要行业')" prop="mainIndustries">
        <el-select v-model="queryParams.mainIndustries" :placeholder="$t('主要行业')" clearable>
          <el-option
            v-for="dict in mainIndustriesOption"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('机构类别')" prop="institutionsCategory">
        <dict-select
          v-model="queryParams.institutionsCategory"
          dictionary="property_Institutions"
          :placeholder="$t('组织形式')"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['property:propertyCompany:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="propertyCompanyList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('公司名称')" align="center" prop="companyId" width="250">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/company/propertyCompany/propertyCompanyHome',query:{id:scope.row.id,companyId : scope.row.id}}"
            class="link_a"
          >{{ scope.row.companyId }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('统一信用代码')" align="center" prop="creditCode" width="300" />
      <el-table-column :label="$t('注册资本') + $t('金额单位')" align="center" prop="registeredCapital" width="180">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.registeredCapital, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('注册资本币种')" align="center" prop="currency" :formatter="currencyFormat" width="180" />
      <el-table-column :label="$t('组织形式')" align="center" prop="organizationalForm" :formatter="organizationalFormFormat" width="180" />
      <el-table-column :label="$t('主要行业')" align="center" prop="mainIndustries" :formatter="mainIndustriesFormat" width="180" />
      <el-table-column :label="$t('机构类别')" align="center" prop="institutionsCategory" :formatter="institutionsFormat" width="180" />
      <el-table-column :label="$t('注册地')" align="center" prop="detailsRegistered" width="300" />
      <el-table-column :label="$t('法定代表人')" align="center" prop="legalPerson" width="180" />
      <el-table-column :label="$t('公司成立日期')" align="center" prop="estiblishDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.estiblishDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('审批状态')" align="center" fixed="right" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" fixed="right" width="200">
        <template slot-scope="scope">
          <!--          <router-link-->
          <!--            target="_blank"-->
          <!--            icon="el-icon-view"-->
          <!--            :to="{path:'/deal/home/dealBaseHome',query:{id:scope.row.dealId,dealType: 'equity', companyId:scope.row.targetCompanyId,menuKey: scope.row.dealStatus, showType: 'deal'}}"-->
          <!--            class="link_a"-->
          <!--          >{{ $t('项目详情') }}</router-link>-->
          <el-button
            v-if="scope.row.dealId"
            v-hasPermi="['property:propertyCompany:edit']"
            size="small"
            type="text"
            icon="el-icon-view"
            @click="updateDeal(scope.row)"
          >{{ $t('项目详情') }}
          </el-button>
          <el-button
            v-if="scope.row.actStatus === 'W'"
            v-hasPermi="['property:propertyCompany:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row,'BG')"
          >{{ $t('变更') }}</el-button>
          <el-button
            v-if="scope.row.actStatus === 'W'"
            v-hasPermi="['property:propertyCompany:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row,'ZX')"
          >{{ $t('注销') }}</el-button>
          <el-button
            v-if="scope.row.actStatus !== 'D' && scope.row.actStatus !== 'W'"
            v-hasPermi="['fund:property:edit']"
            size="small"
            type="text"
            icon="el-icon-video-play"
            @click="updateHandle(scope.row)"
          >{{ $t("启动流程") }}
          </el-button>
          <!--带审批状态下可以终止流程-->
          <el-button
            v-if="scope.row.actStatus === 'D'"
            v-hasPermi="['fund:property:edit']"
            size="small"
            type="text"
            icon="el-icon-video-pause"
            @click="stopProcess(scope.row)"
          >{{ $t("终止流程") }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改产权信息对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <propertyCompanyForm ref="propertyCompanyForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listPropertyCompany, exportPropertyCompany } from '@/api/company/propertyCompany/propertyCompany'
import propertyCompanyForm from './propertyCompanyForm.vue'
export default {
    components: {
        propertyCompanyForm
    },
  data() {
      return {
        currencyOption: [],
        organizationalOption: [],
        mainIndustriesOption: [],
        institutionsOption: [],
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 产权信息表格数据
          propertyCompanyList: [],
          // 弹出层标题
          title: '产权信息',
          // 是否显示弹出层
          formOpen: false,
        // 登记类型(一级)字典
        registrationTypeOptions: [],

        // 经济行批准机构字典
        jcApprovalAgencyOptions: [],

        // 公告方式字典
        jcPublicAnnouncementOptions: [],

        // 转让价款支付方式字典
        jcPricePaymentMethodOptions: [],

        // 新增出资人类型字典
        zzNewInvestorsTypeOptions: [],

          // 查询参数
          queryParams: {
              companyId: undefined,
              creditCode: undefined,
              organizationalForm: undefined,
              mainIndustries: undefined,
              institutionsCategory: undefined,
              last: 'Y',
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()

    this.getDicts('currency').then(response => {
      this.currencyOption = response.data
    })
    this.getDicts('property_organizational').then(response => {
      this.organizationalOption = response.data
    })
    this.getDicts('deal_industry_focus').then(response => {
      this.mainIndustriesOption = response.data
    })
    this.getDicts('property_Institutions').then(response => {
      this.institutionsOption = response.data
    })
      this.getDicts('registration_type').then(response => {
          this.registrationTypeOptions = response.data
      })
      this.getDicts('jc_approval_agency').then(response => {
          this.jcApprovalAgencyOptions = response.data
      })
      this.getDicts('jc_public_announcement').then(response => {
          this.jcPublicAnnouncementOptions = response.data
      })
      this.getDicts('jc_price_payment_method').then(response => {
          this.jcPricePaymentMethodOptions = response.data
      })
      this.getDicts('new_investors_type').then(response => {
          this.zzNewInvestorsTypeOptions = response.data
      })
  },
  methods: {
    /** 查询产权信息列表 */
    getList() {
        this.loading = true
        listPropertyCompany(this.queryParams).then(response => {
            this.propertyCompanyList = response.rows
          this.propertyCompanyList.forEach(item => {
            if (item.dealStatus === 'CB') {
              item.dealStatus = 'deal_pool'
            }
            if (item.dealStatus === 'TQ') {
              item.dealStatus = 'deal_before'
            }
            if (item.dealStatus === 'TH') {
              item.dealStatus = 'deal_before'
            }
            if (item.dealStatus === 'ZZ') {
              item.dealStatus = 'deal_after'
            }
            if (item.dealStatus === 'TC') {
              item.dealStatus = 'deal_after'
            }
              })
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },

    currencyFormat(row) {
      return this.selectDictLabel(this.currencyOption, row.currency)
    },
    organizationalFormFormat(row) {
      return this.selectDictLabel(this.organizationalOption, row.organizationalForm)
    },
    mainIndustriesFormat(row) {
      return this.selectDictLabel(this.mainIndustriesOption, row.mainIndustries)
    },
    institutionsFormat(row) {
      return this.selectDictLabel(this.institutionsOption, row.institutionsCategory)
    },
    // 登记类型(一级)字典翻译
    registrationTypeFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.registrationTypeOptions, row.registrationType)
    },
    // 经济行批准机构字典翻译
    jcApprovalAgencyFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.jcApprovalAgencyOptions, row.jcApprovalAgency)
    },
    // 公告方式字典翻译
    jcPublicAnnouncementFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.jcPublicAnnouncementOptions, row.jcPublicAnnouncement)
    },
    // 转让价款支付方式字典翻译
    jcPricePaymentMethodFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.jcPricePaymentMethodOptions, row.jcPricePaymentMethod)
    },
    // 新增出资人类型字典翻译
    zzNewInvestorsTypeFormat(row, column) {
      console.log(column)
      return this.selectDictLabel(this.zzNewInvestorsTypeOptions, row.zzNewInvestorsType)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            dealId: undefined,
            registrationType: undefined,
            registrationTypeTwo: undefined,
            registrationTypeThree: undefined,
            companyId: undefined,
            creditCode: undefined,
            registeredCapital: undefined,
            currency: undefined,
            organizationalForm: undefined,
            mainIndustries: undefined,
            institutionsCategory: undefined,
            detailsRegistered: undefined,
            legalPerson: undefined,
            estiblishDate: undefined,
            isMergeTable: undefined,
            businessScope: undefined,
            propertyRemark: undefined,
            jcPropertyTrading: undefined,
            jcPropertyTime: undefined,
            jcWithdrawalWay: undefined,
            jcReasonTransfer: undefined,
            jcProportionTransferred: undefined,
            jcTransfereeName: undefined,
            jcTransfereeIndustryType: undefined,
            jcRegistrationPlace: undefined,
            jcIsNationalHoldings: undefined,
            jcAssetValue: undefined,
            jcAssessedValue: undefined,
            jcApprovalAgency: undefined,
            jcForDays: undefined,
            jcPublicAnnouncement: undefined,
            jcTradingVolume: undefined,
            jcEvaluationValue: undefined,
            jcPricePaymentMethod: undefined,
            jcPaymentRemark: undefined,
            xyProportionTransferred: undefined,
            xyTransfereeName: undefined,
            xyRegistrationPlace: undefined,
            xyIsNationalHoldings: undefined,
            xyTransferPrice: undefined,
            wcProportionTransferred: undefined,
            wcTransfereeName: undefined,
            zzNewInvestors: undefined,
            zzNewInvestorsType: undefined,
            zzProportionalCapitalIncrease: undefined,
            zzCompanyValuation: undefined,
            zzAuditedNetAssets: undefined,
            jzCapitalReductions: undefined,
            jzCompanyValuation: undefined,
            jzAuditedNetAssets: undefined,
          targetCompanyId: undefined,
            delFlag: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.propertyCompanyForm.init(null, 'XZ')
        })
    },
    /** 修改按钮操作 */
    updateHandle(row, edit) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.propertyCompanyForm.init(row, edit)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row, edit) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.propertyCompanyForm.init(row, edit)
      })
        // this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        //     confirmButtonText: this.$t('确定'),
        //     cancelButtonText: this.$t('取消'),
        //     type: 'warning'
        // }).then(() => {
        //     return delPropertyCompany(row.id)
        // }).then(() => {
        //     this.getList()
        //     this.msgSuccess(this.$t('删除成功'))
        // }).catch(() => {
        //     this.loading = false
        // })
    },
    stop(data) {
      data.actId = data.id
      this.stopProcess(data)
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return exportPropertyCompany(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(() => {
        })
    },
    // 终止流程按钮是否展示
    stopBtn: function() {
      if (this.busData.actStatus === 'D') {
        return true
      } else {
        return false
      }
    },
    updateDeal(row) {
      const dealHome = this.$router.resolve({
        fromPath: this.$route.fullPath,
        path: '/deal/home/dealBaseHome',
        query: {
          id: row.dealId,
          dealType: 'equity',
          companyId: row.targetCompanyId,
          menuKey: row.dealStatus,
          showType: 'deal'
        }
      })
      // 指定跳转地址
      window.open(dealHome.href, '_blank')
    }
  }
}
</script>
